package com.mspbots.teams.reports.impl;

import com.mspbots.teams.config.ReportsRabbitConfiguration;
import com.mspbots.teams.reports.TeamsMessageReportsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Service
public class TeamsMessageReportsServiceImpl implements TeamsMessageReportsService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sent_message(Long tenantId, String userName) {
        Map<String, Object> msg = new ConcurrentHashMap<>();
        msg.put("tenantId", tenantId);
        msg.put("userName", userName);
        msg.put("msgType", "Message_sent");
        msg.put("msgDatetime", LocalDateTime.now().toString());
        rabbitTemplate.convertAndSend(ReportsRabbitConfiguration.EXCHANGE_NAME, ReportsRabbitConfiguration.MESSAGE_SENT_QUEUE, msg);
    }

    @Override
    public void received_message(Long tenantId, String userName) {
        Map<String, Object> msg = new ConcurrentHashMap<>();
        msg.put("tenantId", tenantId);
        msg.put("userName", userName);
        msg.put("msgType", "Message_received");
        msg.put("msgDatetime", LocalDateTime.now().toString());
        rabbitTemplate.convertAndSend(ReportsRabbitConfiguration.EXCHANGE_NAME, ReportsRabbitConfiguration.MESSAGE_RECEIVED_QUEUE, msg);
    }

    @Override
    public void botsWorking_message(Long tenantId, String userName, Long ruleId) {
        Map<String, Object> msg = new ConcurrentHashMap<>();
        msg.put("tenantId", tenantId);
        msg.put("userName", userName);
        msg.put("botId", ruleId);
        msg.put("msgType", "Bots_working");
        msg.put("msgDatetime", LocalDateTime.now().toString());
        rabbitTemplate.convertAndSend(ReportsRabbitConfiguration.EXCHANGE_NAME, ReportsRabbitConfiguration.BOTS_WORKING_QUEUE, msg);
    }
}
